Polynomial fits using fit_pandas_GUI()

You can try this notebook live by lauching it in Binder.This can take a while to launch, be patient. Binder.

First we import pandas and pandas_GUI and then load some data to fit.

Then make a quick plot using plot_pandas_GUI() to see what the data looks like. See the Pandas GUI Website for examples and documentation on using the plotting GUI.

Figure 1: IR spectrum of ethane with an oscillating baseline.

Fitting the baseline to a polynomial

Looking at this spectrum it appears that the baseline oscillates through zero three time, so a good place to start is to try fitting it to a cubic polynomial.

Start by launching the fitting GUI by putting the command fit_pandas_GUI() in an empty cell and running the cell.

1. On the first tab

the data set and a name for the trace is set. See the screenshot below.

First Tab

2. On the second tab

the default "none" was kept for the Error Type. See the screen shot below.

Tab 2

3. On the third tab

"PolynomialModel" was chosen from the popup menu and coefficients c4 - c7 were fixed at the default value of zero so terms of order higher than 3 were ignored. See the screenshot below.

tab 3

4. On tab 4

the ranges of the data to fit to were chosen to ignore the peaks. Consecutive pairs of selected points starting with the lowest data index number define each range. Points can be deselected by holding down the ctrl key while clicking on a point.

The Extend fitted function plot box was also checked so that the fit is shown in the ignored regions.

See the screenshot below.

tab 4

5. On the fifth tab

labels for the X and Y axis were input and the Display Mirror Axes box was checked.

Fit_tab_5

6. On the last (sixth) tab

the final checks were done and then the 'Do Fit' button was clicked, closing the GUI and running the code in the cell below to perform the fit and display the results.

Fit_tab_6

Figure 2: The results of the fit. Notice that the cubic polynomial was a very good choice. All the parameters appear to have three or four significant figures based on the uncertainties. Zooming in around zero on the residuals shows how well this flattens the baseline. Despite the good baseline correction the spectrometer or sampling methods really need fixing...

Plot of the spectrum with the baseline removed

As the residuals are just the spectrum with the fit subtracted from it we can use that as the corrected spectrum. If I were going to continue working with this spectrum I would add the corrected spectrum to the data frame. I am going to do that below, because it is easiest to make a plot from a data frame using plot_pandas_GUi().

Figure 3: Plot of the baseline corrected spectrum that was added to the data frame from the residuals of the polynomial fit.

Learn More

In addition to trying it below if this is a live notebook, you can look at the other examples listed in the Pandas GUI website.

Try It

If you are running this notebook live in binder you can try it here by running the first cell to import the tools and load the data. Then run the cell below to create the fit GUI. Note: You may want to expand the collapsed instructions to learn more about each tab.